#include<iostream>
#include<algorithm>

using namespace std;
const int N=1e5+10; 
int q[N],hh=0,tt=-1;
string s;
int n;


int main()
{
	cin>>n;
	
	while(n--){
		cin>>s;
		if(s=="push"){
			int x;
			cin>>x;
			q[++tt]=x;
		}
		else if(s=="empty"){
			if(tt<hh) printf("YES\n");
			else  printf("NO\n");
		}
		else if(s=="pop") hh++;
		else printf("%d\n",q[hh]);
	}
	return 0;
}
